<%@ page language="java" pageEncoding="UTF-8" %>
<%@ page import="my.market.display.goods.GetGoodDetail" %>
<%@ page import="my.market.jdbc.dataClass.*" %>
<%@ page import="java.util.Date" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<% RequestDispatcher dispatcher = request.getRequestDispatcher("/getGoodDetail");
	dispatcher.include(request, response); %>
<% Goods good = (Goods)request.getAttribute("find_good"); %>
<% Users user1 = (Users) request.getSession().getAttribute("user");
   HttpSession sess = request.getSession();%>
<html>
<head>
<title><%=good.getName() %></title>
<link type="text/css" href="${pageContext.request.contextPath }/pageDisplay/css/main.css" rel="stylesheet" />
<script type="text/javascript">
	function add_cart(){
		<%	if(user1 == null){%>
		window.alert("请登录之后再进行操作");
		<%	}else{ %>
		<%	List<Goods> cart = (List<Goods>) sess.getAttribute("cart");
			if(cart == null){
				cart = new ArrayList<Goods>();
				sess.setAttribute("cart", cart);
			}
			cart.add(good);%>
		window.alert("已添加至购物车");
		<%	} %>
	}
</script>
<%	if(user1 != null){
		List<History> history = (List<History>) sess.getAttribute("history");
		if(history == null){
			history = new ArrayList<History>();
			sess.setAttribute("history", history);
		}
		History his = new History();
		his.setGoods_id(good.getId());
		his.setMail(user1.getMail());
		his.setBrowse_time(new Date());
		history.add(his);
	}%>
</head>
<body class="main">
<%@include file="head.jsp" %>
<div class="content">
<table>
	<tr>
		<td><%@include file="category.jsp" %></td>
		<td><%@include file="search.jsp" %></td>
	</tr>
</table>
</div>
<div class="content">
<table>
	<tr>
		<td>
			<image src="${pageContext.request.contextPath}/pageDisplay/<%=good.getImageLocation() %>" width="300" height="333"></image>
		</td>
		<td>
			<table>
				<tr>
					<td align="center"><%=good.getName() %></td>
				</tr>
				<tr>
					<td>类型:&nbsp;&nbsp;&nbsp;&nbsp;<%=good.getType() %></td>
				</tr>
				<tr>
					<td>销量:&nbsp;&nbsp;&nbsp;&nbsp;<%=good.getSalesnum() %>次</td>
				</tr>
				<tr>
					<td>描述:<br />&nbsp;&nbsp;&nbsp;&nbsp;<%=good.getDescription() %></td>
				</tr>
				<tr>
					<td>价格:&nbsp;&nbsp;&nbsp;&nbsp;<%=good.getPrice() %>元</td>
				</tr>
				<tr>
					<td><button type="button" onclick="add_cart();">加入购物车</button></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</div>
<%@include file="foot.jsp" %>
</body>
</html>